<template>
    <el-upload
        class="upload-demo"
        ref="upload"
        :action="actionUrl"
        :mutltiple="false"
        :on-success="handleSuccess"
        :on-error="handleError"
        :auto-upload="false"
        :limit="1"
        :on-exceed="handleExceed"
        accept=".xls, .xlsx"
    >
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
        <div class="el-upload_tip">只能上传 xlsx 文件，且一次只能上传一个文件</div>
    </el-upload>
</template>
<script>
export default {
    name: 'YsUpload',
    props: {
        actionUrl: {
            required: true,
            type: String,
        }
    },

    data() {
        return {

        }
    },
    methods: {
        // 导入点击确定按钮
        submitupload() {
            this.$refs.upload.submit();
        },
        handleSuccess(response) {
            if (response.success) {
                this.$message.success('表格导入成功！');
                this.$refs.upload.clearFiles();
                this.$emit('getInitData')
            } else {
                this.$message.error(response.msg);
            }
        },
        handleError(err, file) {
            this.$message.error(err);
        },
        // 文件超出上传个数时钩子
        handleExceed(files) {
            this.$message.error('一次只能上传一份文件,文件选取失败！');
        },
        // 清除上传的文件
        clearFilesFun() {
            this.$refs.upload.clearFiles()
        }
    },
}
</script>
<style scope>
</style>